(function() {
	var $ = require(L('$'));

	module.exports = function(showBack, showSetting, showCancel, title) {
		var pui = $.layout('partial/navbar');
		pui.btnBack.visible = showBack || false;
		pui.btnSetting.visible = showSetting || false;
		pui.btnCancel.visible = showCancel || false;
		pui.title.visible = $.isNull(title) ? false : true;
		pui.lblTitle.text = title;
		pui.onBack = null;

		$.tap(pui.btnBack, function() {
			if (!$.isNull(pui.onBack)) {
				pui.onBack();
				return;
			}
			if (!$.isLoggedIn())
				$.win('home').nav.pop();
			else {
				if ($.needToReloadMyDesires() == true 
					&& ($.currentWindow().wid == L('win_product_details') || $.currentWindow().wid == L('win_ugd_details'))) {
					$.win('my_desires').display();
					$.needToReloadMyDesires(false);
				}
				Ti.UI.currentTab && Ti.UI.currentTab.window.nav.pop();
			}
		});
		$.tap(pui.btnSetting, function() {
			$.win('my_account').nav.reset();
			$.win('my_account').hideView(false);
			$.ui('tabgroup').setActiveTab(4);
			$.win('my_account').nav.push($.win('setting'));
			$.ui('bottom').active(-1);
		});
		$.touch(pui.btnCancel, function() {
			Ti.Media.hideCamera();
			//$.win('ugd/preview').close();
			$.win('ugd/form').close();
		});

		pui.view.overwriteBack = function(handler) {
			pui.onBack = handler;
		};
		pui.view.update = function(showBack, showSetting) {
			pui.btnBack.visible = showBack || false;
			pui.btnSetting.visible = showSetting || false;
		};
		return pui.view;
	};
})();
